<template>
	<view class="page">
		<view class="pageBg">
			<image src="https://bjsx.gzwhir.com/admin-api/infra/file/18/get/memberbg2.png" mode="aspectFill"></image>
		</view>
		<view class="flex0">
			<u-navbar :fixed='false' bgColor="transparent" @leftClick="navBack" title="家长沟通记录">
				<view slot="center" class="navTitle">
					{{attrType[itemid]}}
				</view>
			</u-navbar>
		</view>
		<view class="flex1">
			<scroll-view scroll-y="true" class="scrollView pt30">
				<view class="pd30">
					<view class="appointDetail" v-if="info">
						<view class="wbox">
							<view class="line">
								<view class="ll">
									姓名
								</view>
								<view class="lr">
									{{info.studentName}}
								</view>
							</view>
							<view class="line">
								<view class="ll">
									班级
								</view>
								<view class="lr">
									{{info.gradeName}}{{info.classesName}}
								</view>
							</view>
							<view class="line">
								<view class="ll">
									年龄
								</view>
								<view class="lr">
									{{info.studentAge || ''}}岁
								</view>
							</view>
							<view class="line">
								<view class="ll">
									性别
								</view>
								<view class="lr">
									{{info.studentSex}}
								</view>
							</view>
							<template v-if="itemid==1">
								<view class="line">
									<view class="ll">
										家长姓名
									</view>
									<view class="lr">
										<input type="text" placeholder="请填写家长姓名" v-model="form.name" />
									</view>
								</view>
								<view class="line">
									<view class="ll">
										家长性别
									</view>
									<view class="lr">
										<view class="inlineSelect">
											<uni-data-select v-model="form.sex" :clear="false" :localdata="sexOptions"
												placeholder="选择"></uni-data-select>
										</view>
									</view>
								</view>
								<view class="line">
									<view class="ll">
										家长角色
									</view>
									<view class="lr">
										<view class="inlineSelect">
											<uni-data-select v-model="form.userType" :clear="false" :localdata="roleOptions"
												placeholder="选择"></uni-data-select>
										</view>
									</view>
								</view>
								<view class="line" v-if="form.userType==0">
									<view class="ll">
										其他角色
									</view>
									<view class="lr">
										<input type="text" placeholder="请填写角色" v-model="form.otherUserType" />
									</view>
								</view>
								<view class="line">
									<view class="ll">
										沟通方式
									</view>
									<view class="lr">
										<view class="inlineSelect">
											<uni-data-select v-model="form.communicateMethod" :clear="false"
												:localdata="wayOptions" placeholder="选择"></uni-data-select>
										</view>
									</view>
								</view>
								<view class="line" v-if="form.communicateMethod==4">
									<view class="ll">
										其他方式
									</view>
									<view class="lr">
										<input type="text" placeholder="请填写其他沟通方式" v-model="form.otherCommMethods" />
									</view>
								</view>
							</template>
							<view class="line">
								<view class="ll">
									填表教师
								</view>
								<view class="lr">
									{{personInfo.name}}
								</view>
							</view>
							<view class="line">
								<view class="ll">
									填表时间
								</view>
								<view class="lr">
									<text>{{curDate}}</text>
								</view>
							</view>
						</view>
						
						
						<view class="wbox">
							<view class="lint">
								{{content1Type[itemid]}}
							</view>
							<textarea class="textarea" v-model="form.content01" placeholder="填写过程记录..."></textarea>
						</view>
						<view class="wbox">
							<view class="lint">
								{{content2Type[itemid]}}
							</view>
							<textarea class="textarea" v-model="form.content02" placeholder="填写主要行为..."></textarea>
						</view>

						<template v-if="itemid!=3">
							<view class="wbox">
								<view class="lint">
									{{content3Type[itemid]}}
								</view>
								<textarea class="textarea" v-model="form.content03" placeholder="填写主要行为..."></textarea>
							</view>
						</template>
						<view class="btns">
							<view class="btn" @tap="submit">
								填写完成
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				attrType: ['', '家长沟通记录', '学生沟通记录', '日常观察记录'],
				content1Type: ['', '沟通内容', '沟通主题', '过程记录'],
				content2Type: ['', '家长诉求', '学生反馈', '主要行为'],
				content3Type: ['', '沟通效果', '沟通效果'],
				itemid: '',
				info: '',
				curDate: '',
				sexOptions: [],
				roleOptions: [],
				wayOptions: [],
				taskId: '',
				personInfo: {},
				form: {}
			}
		},
		methods: {
			pad(number, length) {
				var str = "" + number;
				while (str.length < length) {
					str = "0" + str;
				}
				return str;
			},
			getCurDate() {

				var now = new Date();
				var year = now.getFullYear();
				var month = this.pad(now.getMonth() + 1, 2); // 月份是从0开始的
				var day = this.pad(now.getDate(), 2);
				var hours = this.pad(now.getHours(), 2);
				var minutes = this.pad(now.getMinutes(), 2);
				var seconds = this.pad(now.getSeconds(), 2);
				let date = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
				return date
			},
			submit() {
				let post = {
					tasksId: this.taskId,
					...this.form
				}
				this.$api.crisisTaskForm(post, res => {
					if (res.code == 200) {

						this.$common.successToShow('提交成功', () => {
							uni.navigateBack()
						})
					} else {

						this.$common.errorToShow(res.message)
					}
				})

			},
			getInfo() {
				var that = this;
				if (that.itemid) {

					this.$api.crisisTaskInfo({
						id: that.taskId,
						methodType: 'get'
					}, res => {
						if (res.code == 200) {
							this.info = res.data
						}
					})


					this.$api.memberInfo({}, res => {
						if (res.code == 200) {
							this.personInfo = res.data;
						}
					})

				}
			}
		},
		onLoad(e) {
			this.curDate = this.getCurDate()
			if (e.id) {
				this.itemid = e.id
				this.taskId = e.taskId
				this.getInfo();
			}


			this.$api.dictList({
				dictType: 'system_user_sex'
			}, res => {
				if (res.code == 200) {
					res.data.some(item => {
						item.text = item.label
					})
					this.sexOptions = res.data
				}
			})
			this.$api.dictList({
				dictType: 'member_parent_user_type'
			}, res => {
				if (res.code == 200) {
					res.data.some(item => {
						item.text = item.label
					})
					let i={
						text:'其他',
						value:0
					}
					 res.data.push(i)
					this.roleOptions = res.data
				}
			})
			this.$api.dictList({
				dictType: 'crisis_tasks_form_comm_methods'
			}, res => {
				if (res.code == 200) {
					res.data.some(item => {
						item.text = item.label
					})
					this.wayOptions = res.data
				}
			})
		}
	}
</script>

<style lang="scss" scoped>
	.slot-content {
		flex: 0 0 auto;
		width: 100%;
	}

	/deep/.u-popup__content {
		border-radius: 30rpx !important;

		.u-modal__title {
			font-size: 40rpx !important;
			color: #65554d !important;
			padding-top: 40rpx !important;
			line-height: 1;
			font-weight: normal !important;
		}

		.u-modal__content {
			padding: 40rpx 40rpx 0 !important;
		}

		.u-line {
			display: none;
		}

		.u-modal__button-group__wrapper {
			height: 120rpx;
			border-radius: 0 !important;

			.u-modal__button-group__wrapper__text {
				font-size: 28rpx !important;
			}
		}
	}

	.resonTextarea {
		padding: 20rpx;
		height: 300rpx;
		outline: none;
		border: none;
		background: #f9f8f6;
		border-radius: 20rpx;
		font-size: 28rpx;
		color: #897f7a;
		line-height: 1.6;
		width: 100%;
		box-sizing: border-box;
	}

	.appointDetail {
		padding-bottom: 40rpx;

		.tp {
			padding: 40rpx 0 60rpx;

			.ico {
				width: 90rpx;
				height: 90rpx;
				margin: 0 auto 30rpx;

				image {
					display: block;
					width: 100%;
					height: 100%;
				}
			}

			.tit {
				text-align: center;
				font-size: 48rpx;
				font-weight: bold;
				line-height: 1;
				color: #65554d;
				margin-bottom: 20rpx;
			}

			.time {
				text-align: center;
				font-size: 28rpx;
				color: #65554d;
			}
		}

		.btns {
			display: flex;
			align-items: center;
			padding-top: 40rpx;

			.btn {
				flex: 1 1 auto;
				text-align: center;
				line-height: 90rpx;
				height: 90rpx;
				outline: none !important;
				background: #fe9c29;
				color: #fff;
				border: none;
				border-radius: 90rpx;
				overflow: hidden;
				font-size: 28rpx;
				margin-right: 20rpx;

				&:last-child {
					margin-right: 0;
				}

				&:before,
				&:after {
					display: none;
				}

				&.gray {
					background: #fff;
					color: #fe9c29;
					width: 250rpx;
					flex: 0 0 auto;
				}
			}
		}

		.wbox {
			padding: 0 40rpx;
			background: #fff;
			border-radius: 30rpx;
			margin-bottom: 20rpx;
			// overflow: hidden;

			&:last-child {
				margin-bottom: 0;
			}

			.lint {
				font-size: 28rpx;
				padding-top: 30rpx;
				color: #65554d;
				font-weight: bold;
			}

			.textarea {
				border: none;
				background: #fff;
				font-size: 28rpx;
				color: #65554d;
				outline: none;
				line-height: 1.5;
				padding: 30rpx 0 40rpx;
				display: block;
			}

			.dabtn {
				line-height: 100rpx;
				text-align: center;
				background: #ffebd4;
				margin: 0 -40rpx;
				color: #fe9c29;
				font-size: 28rpx;
			}

			.line {
				flex: 0 0 auto;
				display: flex;
				align-items: center;
				height: 100rpx;
				justify-content: space-between;
				border-bottom: 1rpx solid #f7f5f2;
				font-size: 28rpx;

				&:last-child {
					border: none;
				}

				.ll {
					flex: 0 0 auto;
					overflow: hidden;
					padding-right: 30rpx;
					color: #897f7a;
				}

				.lr {
					flex: 1 1 auto;
					display: flex;
					align-items: center;
					text-align: right;
					justify-content: flex-end;
					color: #65554d;

					input {
						font-size: inherit;
						background: none;
						border: none;
						color: inherit;
						width: 100%;
						text-align: right;
					}

					.ico {
						flex: 0 0 auto;
						margin-left: 10rpx;

						image {
							display: block;
							width: 11rpx;
							height: 19rpx;
						}
					}

					.cur {
						flex: 0 0 auto;
					}

					.inlineSelect {
						/deep/ .uni-select {
							border: none;

							.uni-select__input-text {
								font-size: inherit !important;
								text-align: right;
							}

							.uni-select__selector-item {
								justify-content: flex-end;
								display: block;
								white-space: nowrap;
							}

							.uni-popper__arrow_bottom {
								left: auto;
								right: 10%;
							}
						}
					}
				}
			}
		}
	}
</style>